package slidingwindow;

import java.util.HashSet;
import java.util.Set;

public class FriendsOfAppropriateAges825 {
    public int numFriendRequests(int[] ages) {
        Set<String> set = new HashSet<>();
        for (int i = 0; i < ages.length; i++) {
            for (int j = 0; j < ages.length; j++) {
                if (sendFriendRequest(ages, i, j)) {
                    set.add(i + "." + j);
//                    set.add(i > j ? i + "." + j : j + "." + i);
                }
            }
        }
        return set.size() ;
    }

    private boolean sendFriendRequest(int[] ages, int x, int y) {
        if (x == y) {
            return false;
        }
        if ((ages[y] <= (0.5 * ages[x] + 7)) || (ages[y] > ages[x] || (ages[y] > 100 && ages[x] < 100))) {
            return false;
        }
        return true;
    }
}
